#!/bin/bash -e

#此脚本在遇到冲突commit后会先停下来，等冲突解决后，再继续合入。

COMMIT=$1
NUM=$2
TAG=$3

TMP=~
TMPHEAD=$TMP/.head
TMPBODY=$TMP/.body
TMPCOMMENT=$TMP/.comment
BUGZILLA=https://gitee.com/openeuler/kernel/issues/$NUM

function echo_byellow(){
echo -e "\033[33m\033[01m\033[05m[ WARNING: $1 ]\033[0m"
}

SUBJECT=$(git show -s --format="%s" HEAD)

printf "%s\n" "$SUBJECT" > $TMPHEAD
printf "%s\n" "" >> $TMPHEAD
printf "%s\n" "stable inclusion" >> $TMPHEAD
printf "%s\n" "from stable-v5.10.$TAG" >> $TMPHEAD
printf "%s\n" "commit $COMMIT" >> $TMPHEAD
printf "%s\n" "category: bugfix" >> $TMPHEAD
printf "%s\n" "bugzilla: $BUGZILLA" >> $TMPHEAD
#printf "%s\n" "CVE: NA" >> $TMPHEAD
printf "%s\n" "" >> $TMPHEAD
printf "%s\n" "Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=$COMMIT" >> $TMPHEAD
printf "%s\n" "" >> $TMPHEAD
printf "%s\n" "----------------------------------------------------" >> $TMPHEAD

printf "%s\n" "" >> $TMPHEAD

git show -s --format="%b" HEAD > $TMPBODY
sed -i '$d' $TMPBODY
cat $TMPHEAD $TMPBODY > $TMPCOMMENT
git commit -m "$(cat $TMPCOMMENT)" --amend -s
